/**
  ******************************************************************************
  * File Name          : measure_tsk.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "bsp.h"
#include "tskcfg.h"
#include "measure.h"

/* task sync component */
TaskHandle_t xMeasureRt_Thd = NULL;
StaticTask_t xMeasureRt_Tcb;
StackType_t  xMeasureRt_Stk[MEASURE_RT_STACK_SIZE];

TaskHandle_t xMeasureCycle_Thd = NULL;
StaticTask_t xMeasureCycle_Tcb;
StackType_t  xMeasureCycle_Stk[MEASURE_CYCLE_STACK_SIZE];

extern uint32_t gui_mainmenu_refresh_time;

void vMeasureRt_Task(void *pvParameters)
{
  measure_init(&gv);
  
  meas_timetick_init();

  xMeasureCycle_Thd = xTaskCreateStatic(vMeasureCycle_Task, "mscl", MEASURE_CYCLE_STACK_SIZE, (void *)1, \
                                        MEASURE_CYCLE_TSK_PRIORITY, xMeasureCycle_Stk, &xMeasureCycle_Tcb);
  while(1)
  {
    if(ulTaskNotifyTake(pdFALSE, portMAX_DELAY) == pdTRUE)
    {
      measure_real_time(&gv);
    }
  }
}

void vMeasureCycle_Task(void *pvParameters)
{
  TickType_t last_time;

  last_time = xTaskGetTickCount();

//  ao420ma_init();

  while(1)
  {
    measure_cycle(&gv);

    xTaskDelayUntil(&last_time, gui_mainmenu_refresh_time);
  }
}